package com.dao;

import com.entity.game;
import com.entity.product;
import com.entity.productdetails;

import java.util.List;

public class judgeimpl implements judge{

    @Override
    public boolean judgegame(String fgame, String sgame) {
        //查找游戏主类中是否有输入的游戏，没有则返回false，用户无权限增加分类，系统将提示暂不支持此类游戏交易
        boolean flag=false;
        String sql="select * from game where GameName=?";
        UserInfDao u=new UserInfDao();
        List<game> li=u.getForList(game.class,sql,fgame);
        for (int i = 0; i < li.size(); i++) {
            String id=li.get(i).getGameID();
            String sql1="select * from game where FatherGameID=?";
            List<game> list =u.getForList(game.class,sql1,id);
            for (int j = 0; j < list.size(); j++) {
                if(sgame.equals(list.get(j).getGameName()))
                {
                    flag=true;
                    break;
                }
            }
        }
        return flag;
    }

    @Override
    public boolean judgeisonshelve(String sgame, String account, String zone) {
        boolean flag1=true;
        String gID="";
        //根据游戏找到游戏id
        String sql2="select * from game where GameName=?";
        UserInfDao u=new UserInfDao();
        List<game> list1 =u.getForList(game.class,sql2,sgame);
        for (int i = 0; i < list1.size(); i++) {
            if(sgame.equals(list1.get(i).getGameName()))
            {
                gID=list1.get(i).getGameID();
                break;
            }
        }
        //根据游戏id找到productid，根据productid找到游戏的账号account和游戏的区服zone
        //如果找到了，则说明该游戏和区服下，该账号已被注册，返回false
        String sql3="select * from product where GameID=?";
        List<product> list2 =u.getForList(product.class,sql3,gID);
        for (int i = 0; i < list2.size(); i++) {
            String pID=list2.get(i).getProductID();
            String sql4="select * from productdetails where ProductID=?";
            UserInfDao u1=new UserInfDao();
            List<productdetails> list3 =u.getForList(productdetails.class,sql4,pID);
            for (int j = 0; j < list3.size(); j++) {
                if(account.equals(list3.get(j).getAccount())&&zone.equals(list3.get(j).getZone()))
                {
                    flag1=false;
                    break;
                }
            }
        }
        return flag1;
    }
    @Override
    public boolean judgeisexist(String account){
        boolean flag2=false;
        String sql5="select * from productdetails";
        UserInfDao u2=new UserInfDao();
        List<productdetails> list4=u2.getForList(productdetails.class,sql5);
        for (int i = 0; i < list4.size(); i++) {
            if(account.equals(list4.get(i).getAccount()))
            {
                flag2=true;
                break;
            }
        }
        return flag2;
    }

    @Override
    public boolean judgeissh(String id) {
        boolean flag=false;
        String sql="select * from product where ProductID=?";
        UserInfDao u=new UserInfDao();
        List<product> list=u.getForList(product.class,sql,id);
        for (int i = 0; i < list.size(); i++) {
            if("1".equals(list.get(i).getAudit())){
                flag=true;break;
            }
        }
        return flag;
    }
}
